import apiClient from './apiClient'

export const newsService = {
  // 获取资讯分页列表
  getNewsList: async (params) => {
    return await apiClient.get('/news', { params })
  },

  // 获取资讯详情
  getNewsDetail: async (id) => {
    return await apiClient.get(`/news/${id}`)
  },

  // 搜索资讯
  searchNews: async (keyword, page = 1, size = 10) => {
    return await apiClient.get('/news/search', { 
      params: { keyword, page, size } 
    })
  },

  // 创建资讯
  createNews: async (newsData) => {
    return await apiClient.post('/news', newsData)
  },

  // 更新资讯
  updateNews: async (id, newsData) => {
    return await apiClient.put(`/news/${id}`, newsData)
  },

  // 删除资讯
  deleteNews: async (id) => {
    return await apiClient.delete(`/news/${id}`)
  },

  // 更新资讯状态
  updateNewsStatus: async (id, status) => {
    return await apiClient.patch(`/news/${id}/status`, { status })
  },

  // 设置置顶
  setTopNews: async (id, isTop) => {
    return await apiClient.patch(`/news/${id}/top`, { isTop })
  },

  // 获取热门资讯
  getHotNews: async (limit = 5) => {
    return await apiClient.get('/news/hot', { params: { limit } })
  },

  // 获取置顶资讯
  getTopNews: async () => {
    return await apiClient.get('/news/top')
  },

  // 获取最新资讯
  getLatestNews: async (limit = 5) => {
    return await apiClient.get('/news/latest', { params: { limit } })
  },

  // 获取资讯分类列表
  getNewsCategories: async () => {
    return await apiClient.get('/categories/type/news')
  }
}